package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPdf;
import com.ruoyi.system.service.ISysPdfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/pdf")
public class SysPdfController extends BaseController {

    @Autowired
    private ISysPdfService service;

    @GetMapping("/list")
    public TableDataInfo list(SysPdf pdf)
    {
        startPage();
        List<SysPdf> list = service.selectPdfList(pdf);
        return getDataTable(list);
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(service.selectPdfById(id));
    }

    @Log(title = "PDF", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysPdf pdf)
    {
        pdf.setCreateBy(getUsername());
        return toAjax(service.insertPdf(pdf));
    }

    @Log(title = "PDF", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysPdf pdf)
    {
        pdf.setUpdateBy(getUsername());
        return toAjax(service.updatePdf(pdf));
    }

    @Log(title = "PDF", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.deletePdfByIds(ids));
    }
}
